package com.tensquare.service;

import com.tensquare.dao.SpitDao;
import com.tensquare.entity.PageResult;
import com.tensquare.entity.Spit;
import com.tensquare.util.IdWork;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.UUID;

@Service
public class SpitService {

    @Autowired
    SpitDao spitDao;

    @Autowired
    IdWork idWork;

    /**
     * 分页查询所以记录
     * @param
     * @return
     */
    public List<Spit> findAll(int page, int limit){
        PageResult pageResult = new PageResult();
        pageResult.setCurrentPage(page);
        pageResult.setLimit(limit);

        return spitDao.findAll(pageResult);
    }

    /**
     * 根据主键id查询记录
     * @param id
     * @return
     */
    public Spit findById(String id){
        return spitDao.findById(id);
    }

    public List<Spit> findByParentid(String parentid, int page, int limit){
        PageResult pageResult = new PageResult();
        pageResult.setCurrentPage(page);
        pageResult.setLimit(limit);
        return spitDao.findByParentid(pageResult, parentid);
    }

    /**
     * 新增吐槽记录
     * @param spit
     */
    public void add(Spit spit){
        spit.setId(idWork.nextId());

        spitDao.add(spit);
    }

    /**
     * 更新记录
     * @param spit
     */
    public void update(Spit spit){


        spitDao.update(spit);
    }

    /**
     * 文章点赞
     * @param id
     */
    public void updateThumbup(String id){
        spitDao.updateThumbup(id);
    }


    /**
     * 根据id删除记录
     * @param id
     */
    public void delete(String id){
        spitDao.delete(id);
    }
}
